
package com.jf.cloud.user.controller.multishop;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.user.dto.UserRechargeDTO;
import com.jf.cloud.user.model.UserRecharge;
import com.jf.cloud.user.service.UserRechargeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 余额充值级别表
 *
 * @author zz
 * @date 2021-04-27 15:51:36
 */
@RestController("multishopUserRechargeController")
@RequestMapping("/m/user_recharge")
@Tag(name = "余额充值级别表")
public class UserRechargeController {

    @Autowired
    private UserRechargeService userRechargeService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取余额充值级别表列表" , description = "分页获取余额充值级别表列表")
    public ServerResponseEntity<PageVO<UserRecharge>> page(@Valid PageDTO pageDTO) {
        PageVO<UserRecharge> userRechargePage = userRechargeService.page(pageDTO);
        return ServerResponseEntity.success(userRechargePage);
    }


    @PostMapping
    @Operation(summary = "保存余额充值级别表" , description = "保存余额充值级别表")
    public ServerResponseEntity<Void> save(@Valid @RequestBody UserRechargeDTO userRechargeDTO) {
        UserRecharge userRecharge = mapperFacade.map(userRechargeDTO, UserRecharge.class);
        userRecharge.setRechargeId(null);
        userRechargeService.save(userRecharge);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新余额充值级别表" , description = "更新余额充值级别表")
    public ServerResponseEntity<Void> update(@Valid @RequestBody UserRechargeDTO userRechargeDTO) {
        UserRecharge userRecharge = mapperFacade.map(userRechargeDTO, UserRecharge.class);
        userRechargeService.update(userRecharge);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除余额充值级别表" , description = "根据余额充值级别表id删除余额充值级别表")
    public ServerResponseEntity<Void> delete(@RequestParam Long rechargeId) {
        userRechargeService.deleteById(rechargeId);
        return ServerResponseEntity.success();
    }
}
